#if 0
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct Cmp
{
	bool operator()(const pair<int,int>& l,const pair<int,int>& r)
	{
		return l.first > r.first;
	}
};
vector<int> regroup(vector<vector<int>>& inputs,int maxcount)
{
	int n = inputs.size();
	if (n == 0 || maxcount < 0)
		return vector<int>();

	//key:元素  value:在inputs当中的哪个下标对应的容器中
	priority_queue<pair<int,int>,vector<pair<int,int>>,Cmp> pq;
	vector<int> monitor(n, 0); //监视数组
	vector<int> ans;
	for (int i = 0; i < n; i++)
	{
		int size = inputs[i].size();
		if (size != 0)
			pq.push(make_pair(inputs[i][0],i));
	}

	while (!pq.empty() && maxcount--) 
	{
		pair<int,int> kv = pq.top(); 
		int val = kv.first; //元素值
		int index = kv.second;//该元素在哪个容器中
		pq.pop();
		ans.push_back(val);

		//monitor[i] = index:表示当前inputs[i]号位置的容器遍历到了index位置

		monitor[index]++; //monitor[index]：当前inputs[index]容器遍历到的位置
		if (monitor[index] < inputs[index].size()) //inputs[index]容器还有元素
			pq.push(make_pair(inputs[index][monitor[index]], index));
	}
	cout << ans.size() << endl;
	return ans;
}


void Test()
{
	vector<vector<int>> vv1{
		{1,2,5},
		{2,5},
		{6,8}
	};

	vector<vector<int>> vv2{
		{1,2,5},
		{4,7,10},
		{}
	};



	vector<int> tmp = regroup(vv1, 7);
	for (auto& x : tmp)
		cout << x << " ";
	cout << endl;


	tmp = regroup(vv2, 8);
	for (auto& x : tmp)
		cout << x << " ";
	cout << endl;
}
int main()
{
	Test();
	return 0;
}